
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

eyecmd_printf = binder_py('mx_eyecmd_printf')
eyecmd_printf.mx_c.headers = ['<eyelink.h>','"mex.h"']
eyecmd_printf.bindo += []
eyecmd_printf.mx_c.code = \
""" 
INT16 _main( char FARTYPE *msg )
{
    return eyecmd_printf( msg );
    return 1;
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    char FARTYPE *msg;

    /* Verify input arguments. */
    if(nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
           
    if (!mxIsChar(prhs[0]))
        mexErrMsgTxt("msg should be a string.");
   
    msg = mxArrayToString( prhs[0] );
    
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
    
    *status = (double ) _main( msg );

    mxFree(msg);

    return;
}
"""

eyecmd_printf.mx_c.mdoc = \
"""function [ ] = mx_eyecmd_printf( )
%MX_EYECMD_PRINTF The EyeLink tracker accepts text commands through the link.
% These commands may be used to configure the system, open data files, and so on.
%
% Remarks:
% The function waits up to 500 msec. for a success or failure code to be returned from the tracker, then returns the error code NO_REPLY. If you need more time, use eyelink_timed_command() instead.
% Parameters:
% fmt 	Similar to printf(), format string plus arguments.
% Returns:
% 0 if successfully executed, else error code.
%
"""
eyecmd_printf.write_c()
eyecmd_printf.write_m()
eyecmd_printf.compile()
eyecmd_printf.write_sh()

